Draws a 1-pixel-thick, axis-aligned outline (never filled) w wide and h tall, with its top-left corner at (x, y) - world space, scrolling with the camera the same way draw_rect_fill does. Inside a Draw GUI event it is fixed to the screen instead, and (x, y) counts from the screen’s top-left pixel.
Works differently on Game Boy - A rectangle on the Game Boy is made of sprites and drawn in the 4 shades: red, blue and magenta come out dark grey, green, yellow, cyan and white light grey. It shares the 40 sprites on the screen (10 a line); a big box is cut short.
Works differently on Game Boy Color - Rectangles are made of sprites and share the 40 on the screen (10 a line): bars, frames and small boxes are exact, a big box is cut short. Colors come 3 to a free sprite palette, others become the nearest. On the screen they are behind sprites and text.
On other consoles this differs: see Side by side and How the consoles differ.
draw_rect(x, y, w, h, color)| Name | Type |
|---|---|
x | real |
y | real |
w | real |
h | real |
color | shape_color |
Nothing.
Draws a 1-pixel-thick, axis-aligned outline w pixels wide and h pixels tall, with its top-left corner at (x, y) - never filled. World space, scrolling with the camera the same way draw_sprite does. In a Draw GUI event the same call is fixed to the screen instead, and (x, y) counts from the screen's top-left pixel - a selection box around a menu item, a border for a health-bar backing, a frame pinned to a corner.
The counting starts at the room's top-left corner, so (x, y) is a place in the room, counted from the room's top-left corner, and it is where the outline's own top-left corner goes. A rectangle has no origin to pick (a sprite does), so it always goes by its corner.
Like draw_rect_fill, this is a real sprite, not paint: the Game Boy Advance has no per-pixel drawing surface. An outline is built from the same shared shape sprite, stretched thin along each edge instead of over the whole box.
color is one of COLOR_WHITE, COLOR_BLACK, COLOR_RED, COLOR_GREEN, COLOR_BLUE, COLOR_YELLOW, COLOR_CYAN, COLOR_MAGENTA.
draw_rect(x - mask_w / 2, y - mask_h / 2, mask_w, mask_h, COLOR_YELLOW);A yellow box the exact size of this instance's own collision mask, drawn every frame this Draw event runs - a hand-rolled version of what show_collision already does for you in one call, useful when you want a different color or size than the real mask.
Up to 4 OAM sprites (one per side) and up to 2 affine matrices - one shared by the top+bottom pair, one shared by the left+right pair, never 4. Sharing a matrix across a same-scale pair is the whole reason this is a dedicated function rather than four calls to draw_rect_fill: four separate calls would need up to 4 matrices, since each one is its own independent cache entry with no idea the other three exist.
An outline's bars are 1 pixel thick, and the hardware has no native OBJ shape thinner than 8 pixels on either axis - so unlike draw_rect_fill's own w == h == 8 shortcut, an outline always wants at least one matrix per pair, for as long as it keeps being drawn. If a pair cannot get a matrix, that whole pair (both its bars) draws nothing this frame rather than the wrong thickness - never just one side left dangling.
A side longer than 16 pixels (and a side 6, 10, 12 or 14 long) is drawn from plain sprites laid end to end instead, so an outline of any size is complete - a 120 by 6 frame round a boss bar shows all four sides. Those sprites are the sprite's own size, never stretched, so a long side needs no matrix at all: it costs one sprite for every 32 pixels of a side (a 120 pixel side is four sprites, and an outline has two of each side), and one of the "things your code draws at once" in Project Settings for every 12 of those sprites. A long side also spends the console's drawing time (a row of the screen can only hold so much): a long outline with a lot else drawn on the same rows of the screen can lose the end of a side, the same as a big filled rectangle. A side longer than 1,024 pixels is drawn 1,024 long.
0 or negative w/h is clamped to 1 pixel, never a crash.
Up to 4 OAM sprites (one per side) and up to 2 affine matrices - one shared by the top+bottom pair, one shared by the left+right pair, never 4 (see draw_rect_fill's own note on why a plain 8x8 call is the one size that needs no matrix at all - an outline's bars are never that size, so this always wants at least the 2). If a pair cannot get a matrix, that WHOLE pair (both its bars) draws nothing this frame rather than the wrong thickness - never just one side. A side longer than 16 pixels (or 6, 10, 12 or 14 long) is drawn from plain sprites laid end to end, never stretched: no matrix at all, one sprite per 32 pixels of a side (two sides of each length), one draw-cache entry per 12 of those sprites, and up to 1,024 pixels a side. A long outline with a lot else drawn on the same rows of the screen can lose the end of a side (the console draws a row only while it has time left).